<template>
    <el-container class="HomeContainer">
      <!--  左侧-->
      <el-aside :width='isCollapse? "64px" : "240px"' class="leftBox">
        <div class="logoBox">
          <img src="../assets/logo.png">
        </div>
        <!--侧边栏-->
        <el-menu
          :default-active="activePath"
          class="el-menu-vertical-demo" background-color="#334157" text-color="#fff" active-text-color="#ffd04b" unique-opened :collapse="isCollapse" router>
          <!-- 一级菜单-->
          <el-submenu :index="item.path" v-for="item in menulist" :key="item.id">
            <!-- 一级菜单模板区域-->
            <template slot="title">
              <!-- 图标-->
              <i class="el-icon-location"></i>
              <!-- 文本-->
              <span>{{ item.authName }}</span>
            </template>
            <!-- 二级菜单-->
            <el-menu-item :index="e.path" v-for="e in item.children" :key="e.id" @click="saveNavState(e.path)">
              <template slot="title">
                <!-- 图标-->
                <i class="el-icon-menu"></i>
                <!-- 文本-->
                <span>{{ e.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!--  主体-->
      <el-container>
        <!--顶部-->
        <el-header>
          <el-button @click="toggleCollapse" class="btnNavClose">
            <i class=" iconfont icon-a-217shijian-xianxing"></i>
          </el-button>
          <el-menu class="el-menu-demo" mode="horizontal" background-color="#334157" text-color="#fff" active-text-color="#fff">
          <el-submenu index="2" class="submenu">
            <!-- <template slot="title">{{user.userRealName}}</template> -->
            <template slot="title">超级管理员</template>
            <el-menu-item index="2-1">设置</el-menu-item>
            <el-menu-item index="2-2">个人中心</el-menu-item>
            <el-menu-item @click="logout" index="2-3">退出</el-menu-item>
          </el-submenu>
          </el-menu>
        </el-header>
        <!-- 主体内容-->
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
</template>
<script>
import navData from '@/mock.js'
export default {
  data () {
    return {
      menulist: [],
      isCollapse: false,
      activePath: ''
    }
  },
  created () {
    this.getNavList()
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  methods: {
    logout () {
      window.sessionStorage.clear()
      this.$router.push('login')
    },
    getNavList () {
      this.menulist = navData
    },
    toggleCollapse () {
      this.isCollapse = !this.isCollapse
    },
    saveNavState(activePath) {
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    }
  }
}
</script>

<style lang="less" scoped>
.HomeContainer{ height: 100%;}
.el-header{  background: #334157; display: flex; justify-content: space-between; align-items: center; color: #fff;box-shadow: 2px 2px 5px gray;}
.leftBox{
  box-shadow: 2px 2px 5px gray;
  .logoBox{  height: 40px;
    //line-height: 40px;
    //color: #9d9d9d;
    //font-size: 20px;
    text-align: center;
    padding: 20px 0px;
    img{
      width: 30px;
      height: 30px; margin-right: 20px;
    }
  }
}
.el-aside{
  background-color: #334157;
}
.el-menu-vertical-demo {
  width: 240px;
  min-height: 400px;
}
.btnNavClose{
  height: 60px;
  background-color: transparent;
  border: none;
  padding-left: 0;
  i{
    font-size: 30px;
    color: #fff;
  }
}
.submenu {
  float: right;
}

</style>
